import threading
from time import ctime, sleep


loops = [4, 2]


class MyThread(threading.Thread):

    def __init__(self, func, args, name=''):
        threading.Thread.__init__(self)
        self.func = func
        self.args = args
        self.name = name

    def run(self):
        self.func(*self.args)


def loop(nloop, nsec):
    print(f'loop {nloop} start at: {ctime()}')
    sleep(nsec)
    print(f'loop {nloop} end at: {ctime()}')


def main():
    print(f'loop start at: {ctime()}')
    threads = []
    nloops = range(len(loops))

    for i in nloops:
        t = MyThread(loop, (i, loops[i]), loop.__name__)
        threads.append(t)

    for i in nloops:
        threads[i].start()

    for i in nloops:
        threads[i].join()

    print(f'all done at {ctime()}')


if __name__ == "__main__":
    main()